package com.punai.evaluationSystem.costDataEvalute.controller;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.evaluationSystem.costDataEvalute.bo.CostDataEvaluteBo;
import com.punai.evaluationSystem.costDataEvalute.bo.EvaluationDataPriceBo;
import com.punai.evaluationSystem.costDataEvalute.constants.CostDataEvaluteConstanta;
import com.punai.evaluationSystem.costDataEvalute.domain.EvaluationResults;
import com.punai.evaluationSystem.costDataEvalute.service.FeeItemPriceEvaluteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用项价格评价
 *
 * @author tj
 * @date 2023-04-25
 */
@RestController
@RequestMapping("/costDataEvalute/priceEvalute")
public class FeeItemPriceEvaluteController extends BaseController {
    @Autowired
    private FeeItemPriceEvaluteService feeItemPriceEvaluteService;

    /**
     * 查询页签列表
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @GetMapping("/getTabs")
    public AjaxResult getTabs() {
        return AjaxResult.success(CostDataEvaluteConstanta.Tabs.getAllTab());
    }

    /**
     * 查询结果列表
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/resultList")
    public TableDataInfo list(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        List<EvaluationResults> list = feeItemPriceEvaluteService.initResultsSrTable(costDataEvaluteBo);
        return getDataTable(list);
    }

    /**
     * 保存资产库
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:edit')")
    @PostMapping("/saveAssetLibrary")
    public AjaxResult saveAssetLibrary(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        int i = feeItemPriceEvaluteService.saveAssetLibrary(costDataEvaluteBo.getList());
        return toAjax(i);
    }

    /**
     * 查询清洗数据列表
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/cleanDataList")
    public TableDataInfo cleanDataList(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return getDataTable(feeItemPriceEvaluteService.initCleanDataTable(costDataEvaluteBo));
    }

    /**
     * 查询清洗数据编辑列表
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/cleanDataEvaluteList")
    public TableDataInfo cleanDataEvaluteList(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return feeItemPriceEvaluteService.initCleanDataEvaluteTable(costDataEvaluteBo);
    }

    /**
     * 重新计算
     * @param costDataEvaluteBo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/recalculation")
    public AjaxResult recalculation(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        EvaluationDataPriceBo recalculation = feeItemPriceEvaluteService.recalculationPrice(costDataEvaluteBo);
        return AjaxResult.success(recalculation);
    }

    /**
     * 保存评价价格
     * @param costDataEvaluteBo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:save')")
    @PostMapping("/saveEvaluationPrice")
    public AjaxResult saveEvaluationPrice(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        int i = feeItemPriceEvaluteService.saveEvaluationPrice(costDataEvaluteBo);
        return toAjax(i);
    }

    /**
     * 所有明细id
     * @param costDataEvaluteBo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/cleanDataInfoIdList")
    public TableDataInfo cleanDataInfoIdList(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return getDataTable(feeItemPriceEvaluteService.cleanDataInfoIdList(costDataEvaluteBo));
    }

    /**
     * 详情表格
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/initTableDetailInfoData")
    public TableDataInfo initTableDetailInfoData(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return getDataTable(feeItemPriceEvaluteService.initTableDetailInfoData(costDataEvaluteBo));
    }

    /**
     * 查看详情列表
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/initEvaluteDataList")
    public TableDataInfo initEvaluteDataList(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return getDataTable(feeItemPriceEvaluteService.initEvaluteDataList(costDataEvaluteBo));
    }

    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:list')")
    @PostMapping("/evaluteDataInfoIdList")
    public TableDataInfo evaluteDataInfoIdList(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        return getDataTable(feeItemPriceEvaluteService.evaluteDataInfoIdList(costDataEvaluteBo));
    }

    /**
     * 修改评价价格
     * @param costDataEvaluteBo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('costDataEvalute:priceEvalute:edit')")
    @PostMapping("/updateEvaluationPrice")
    public AjaxResult updateEvaluationPrice(@RequestBody CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        int i = feeItemPriceEvaluteService.updateEvaluationPrice(costDataEvaluteBo);
        return toAjax(i);
    }

    @GetMapping("/getAllPjjg")
    public AjaxResult getAllPjjg(CostDataEvaluteBo costDataEvaluteBo)
    {
        costDataEvaluteBo.setCompanyId(getCompanyId());
        List<EvaluationResults> result = feeItemPriceEvaluteService.findAllPjjg(costDataEvaluteBo);
        return AjaxResult.success(result);
    }
}
